<template>
	<view>
		<mescroll-body-diy ref="mescrollRef" @init="mescrollInit" top="10" bottom="10" :down="downOption" @down="downCallback" @up="upCallback">
			<!-- 分页的数据 -->
			<articlebox v-for="news in dataList" :article_info="news" :key="news.id"></articlebox>
		</mescroll-body-diy>
	</view>
</template>

<script>
import articlebox from '@/components/article_box.vue';
import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js';
import MescrollBodyDiy from '@/uni_modules/mescroll-uni/components/mescroll-body/mescroll-body.vue';

export default {
	mixins: [MescrollMixin], // 使用mixin
	components: {
		articlebox,
		MescrollBodyDiy
	},
	data() {
		return {
			downOption: {
				auto: false //是否在初始化完毕之后自动执行下拉回调callback; 默认true
			},
			dataList: [], // 数据列表
			pageNum: 1,
			isLogin: 0
		};
	},
	onShow(){
		const token = uni.getStorageSync('token');
		if (token && typeof token != 'undefined') {
			this.isLogin = 1;
		} else {
			this.isLogin = 0;
		}
	},
	methods: {
		/*下拉刷新的回调 */
		downCallback(page) {
			this.pageNum = 1
			this.dataList = []
			this.mescroll.resetUpScroll()
		},
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback() {
			let pageNum = this.pageNum; // 页码
			this.$u.api
				.getWeiboList({ pageNum: pageNum })
				.then(data => {
					// 接口返回的当前页数据列表 (数组)
					const curPageData = data.curPageData;

					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					this.mescroll.endSuccess(curPageData.length);
					//追加新数据
					this.dataList = this.dataList.concat(curPageData);
					// 页码加1
					this.pageNum++;
				})
				.catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				});
		}
	}
};
</script>
<style>
/* #ifndef H5 */
page {
	height: 100%;
	background-color: #f2f2f2;
}
/* #endif */
.imgPoPContent {
	width: 750rpx;
}
</style>
